home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
program
/
recio212.zip
/
rputf.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-01-29
|
2KB
|
69 lines
/*****************************************************************************
MODULE: rputf.c
PURPOSE: recio character delimited floating point output functions
COPYRIGHT: (C) 1994-1995, William Pierpoint
COMPILER: Borland C Version 3.1
OS: MSDOS Version 6.2
VERSION: 2.12
RELEASE: January 29, 1995
*****************************************************************************/
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "recio.h"
extern char *dtoa(double d, char *str, int dig);
extern int _risready(REC *rp, int mode);
extern int _rputc(REC *rp, int ch);
#define rfp(rp) ((rp)->r_fp)
#define rcol(rp) ((rp)->r_colno)
#define rfldch(rp) ((rp)->r_fldch)
#define rflags(rp) ((rp)->r_flags)
/****************************************************************************/
static void /* returns nothing */
_rputd( /* output floating point number to rec stream */
REC *rp, /* pointer to record stream */
int dig, /* number of significant digits */
double num) /* floating point number */
/****************************************************************************/
{
if (_risready(rp, R_WRITE)) {
rfldno(rp)++;
rflags(rp) &= ~_R_TXT;
/* if not first field, put field separator if not null */
if (rfldno(rp) > 1 && rfldch(rp)) {
if (_rputc(rp, rfldch(rp))) goto done;
}
/* convert number to string */
dtoa(num, _r_nsbuf, dig);
/* output converted string */
if (fputs(_r_nsbuf, rfp(rp)) != EOF) {
rcol(rp) += strlen(_r_nsbuf);
} else {
rseterr(rp, R_ENOPUT);
}
}
done:
}
/****************************************************************************/
/* character delimited floating point output functions */
/****************************************************************************/
void rputf(REC *rp, float num)
{
_rputd(rp, FLT_DIG, (double) num);
}
void rputd(REC *rp, double num)
{
_rputd(rp, DBL_DIG, num);
}